/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.scm.rmpm.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 *
 * @author Zhang Ying & Yuwei
 */
@Entity
public class RawMaterial implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    private Long leadtime;
    private Long lotSize;
    private String acronym;
    private Long shelfLife;
    @OneToMany(targetEntity = RawMaterialSupplyInformation.class, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER, mappedBy = "rawMaterial")
    private List<RawMaterialSupplyInformation> supplies;

    public RawMaterial() {
        name = "";
        leadtime = 0L;
        lotSize = 0L;
    }

    public RawMaterial(String name, Long leadtime, Long lotSize) {
        this.name = name;
        this.leadtime = leadtime;
        this.lotSize = lotSize;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getLeadtime() {
        return leadtime;
    }

    public void setLeadtime(Long leadtime) {
        this.leadtime = leadtime;
    }

    public Long getLotSize() {
        return lotSize;
    }

    public void setLotSize(Long lotSize) {
        this.lotSize = lotSize;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAcronym() {
        return acronym;
    }

    public void setAcronym(String acronym) {
        this.acronym = acronym;
    }

    public Long getShelfLife() {
        return shelfLife;
    }

    public void setShelfLife(Long shelfLife) {
        this.shelfLife = shelfLife;
    }

    public List<RawMaterialSupplyInformation> getSupplies() {
        return supplies;
    }

    public void setSupplies(List<RawMaterialSupplyInformation> supplies) {
        this.supplies = supplies;
    }

    public void setRawMaterialAcronymAndShelfLife() {

        if (name.equals("Oats")) {
            this.acronym = "OT";
            this.shelfLife = 12L;
        }
        if (name.equals("Wheat Germ")) {
            this.acronym = "WG";
            this.shelfLife = 12L;
        }
        if (name.equals("Cinnamon")) {
            this.acronym = "CM";
            this.shelfLife = 12L;
        }
        if (name.equals("Nutmeg")) {
            this.acronym = "NM";
            this.shelfLife = 12L;
        }
        if (name.equals("Cloves")) {
            this.acronym = "CL";
            this.shelfLife = 12L;
        }
        if (name.equals("Honey")) {
            this.acronym = "HO";
            this.shelfLife = 12L;
        }
        if (name.equals("Canola Oil")) {
            this.acronym = "CO";
            this.shelfLife = 12L;
        }
        if (name.equals("Vitamin/Mineral Powder")) {
            this.acronym = "VM";
            this.shelfLife = 12L;
        }
        if (name.equals("Carob Chips")) {
            this.acronym = "CC";
            this.shelfLife = 12L;
        }
        if (name.equals("Protein Powder")) {
            this.acronym = "PP";
            this.shelfLife = 12L;
        }
        if (name.equals("Cocoa Powder")) {
            this.acronym = "CP";
            this.shelfLife = 24L;
        }
        if (name.equals("Hazenuts")) {
            this.acronym = "HM";
            this.shelfLife = 24L;
        }
        if (name.equals("Cashew Nuts")) {
            this.acronym = "CN";
            this.shelfLife = 24L;
        }
        if (name.equals("Walnuts")) {
            this.acronym = "WN";
            this.shelfLife = 24L;
        }
        if (name.equals("Almonds")) {
            this.acronym = "AL";
            this.shelfLife = 24L;
        }
        if (name.equals("Macadamias")) {
            this.acronym = "MD";
            this.shelfLife = 24L;
        }
        if (name.equals("Redcurrants")) {
            this.acronym = "RD";
            this.shelfLife = 6L;
        }
        if (name.equals("Rasins")) {
            this.acronym = "RS";
            this.shelfLife = 12L;
        }
        if (name.equals("Dates")) {
            this.acronym = "DT";
            this.shelfLife = 12L;
        }
        if (name.equals("Apricots")) {
            this.acronym = "AR";
            this.shelfLife = 6L;
        }
        if (name.equals("Kiwis")) {
            this.acronym = "KW";
            this.shelfLife = 6L;
        }
        if (name.equals("Apples")) {
            this.acronym = "AP";
            this.shelfLife = 6L;
        }
        if (name.equals("Peaches")) {
            this.acronym = "PE";
            this.shelfLife = 6L;
        }
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof RawMaterial)) {
            return false;
        }
        RawMaterial other = (RawMaterial) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.scm.rmpm.entity.RawMaterial[ id=" + id + " ]";
    }

 
}
